home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / sail.tar / sail / dr_5.c < prev    next >
C/C++ Source or Header  |  1992-09-18  |  2KB  |  73 lines

  1. /*
  2.  * Copyright (c) 1983 Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms are permitted
  6.  * provided that this notice is preserved and that due credit is given
  7.  * to the University of California at Berkeley. The name of the University
  8.  * may not be used to endorse or promote products derived from this
  9.  * software without specific prior written permission. This software
  10.  * is provided ``as is'' without express or implied warranty.
  11.  */
  12.  
  13. #ifndef lint
  14. static char sccsid[] = "@(#)dr_5.c    5.2 (Berkeley) 3/9/88";
  15. #endif /* not lint */
  16.  
  17. #include "externs.h"
  18.  
  19. subtract(from, totalfrom, crewfrom, fromcap, pcfrom)
  20. struct ship *from, *fromcap;
  21. int pcfrom;
  22. register int  totalfrom, crewfrom[3];
  23. {
  24.     register int n;
  25.  
  26.     if (fromcap == from && totalfrom) {        /* if not captured */
  27.         for (n = 0; n < 3; n++) {
  28.             if (totalfrom > crewfrom[n]) {
  29.                 totalfrom -= crewfrom[n];
  30.                 crewfrom[n] = 0;
  31.             } else {
  32.                 crewfrom[n] -= totalfrom;
  33.                 totalfrom = 0;
  34.             }
  35.         }
  36.         Write(W_CREW, from, 0, crewfrom[0], crewfrom[1], crewfrom[2], 0);
  37.     } else if (totalfrom) {
  38.         pcfrom -= totalfrom;
  39.         pcfrom = pcfrom < 0 ? 0 : pcfrom;
  40.         Write(W_PCREW, from, 0, pcfrom, 0, 0, 0);
  41.     }
  42. }
  43.  
  44. mensent(from, to, crew, captured, pc, isdefense)
  45. struct ship *from, *to, **captured;
  46. int crew[3], *pc;
  47. char isdefense;
  48. {                    /* returns # of crew squares sent */
  49.     int men = 0;
  50.     register int n;
  51.     int c1, c2, c3;
  52.     register struct BP *bp;
  53.  
  54.     *pc = from->file->pcrew;
  55.     *captured = from->file->captured;
  56.     crew[0] = from->specs->crew1;
  57.     crew[1] = from->specs->crew2;
  58.     crew[2] = from->specs->crew3;
  59.     bp = isdefense ? from->file->DBP : from->file->OBP;
  60.     for (n=0; n < NBP; n++, bp++) {
  61.         if (bp->turnsent && bp->toship == to)
  62.             men += bp->mensent;
  63.     }
  64.     if (men) {
  65.         c1 = men/100 ? crew[0] : 0;
  66.         c2 = (men%100)/10 ? crew[1] : 0;
  67.         c3 = men/10 ? crew[2] : 0;
  68.         c3 = *captured == 0 ? crew[2] : *pc;
  69.     } else
  70.         c1 = c2 = c3 = 0;
  71.     return(c1 + c2 + c3);
  72. }
  73.